package firstTry;

import java.awt.image.BufferedImage;

public class Heli extends Sprite {

	public Heli(BufferedImage[] i, double x, double y, long delay, GamePanel p) {
		super(i, x, y, delay, p);
	}

	
	public void doLogic(long delta){
		super.doLogic(delta);
		
		if(getX()<0){
			setHorizontalSpeed(0);
			setX(0);	
		}
		if(getX()+getWidth()>parent.getWidth()){
			setHorizontalSpeed(0);
			setX(parent.getWidth()-getWidth());
		}
		
		if(getY()<0){
			setVerticalSpeed(0);
			setY(0);	
		}
		if(getY()+getHeight()>parent.getHeight()){
			setVerticalSpeed(0);
			setY(parent.getHeight()-getHeight());
		}
		
	}


	@Override
	public boolean collidedwith(Sprite s) {

		if(remove)
			return false;
		
		if(this.intersects(s)){
			
			if (s instanceof Rocket){
				if(super.checkOpaqueColorCollisions(s)){
				parent.createExplosion((int)getX(), (int)getY());
				parent.createExplosion((int)s.getX(), (int)s.getY());
				
				remove = true;
				s.remove = true;
				parent.gameover = System.currentTimeMillis();
				}
			}
			
			return true;
		}
		
		return false;
	}
	
	
}
